﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace Harkon.AppServer.cOne.Service
{
    [DataContract]
    public class ServiceName
    {
        [DataMember]
        public string Name { get; private set; }

        [DataMember]
        public string Component { get; private set; }

        [DataMember]
        public string Contract { get; private set; }

        public ServiceName(string name, string component, string contract)
        {
            Name = name;
            Component = component;
            Contract = contract;
        }

        public ServiceName(string name, ComponentInformation componentInformation, string contract)
        {
            Name = name;
            Component = componentInformation.Name;
            Contract = contract;
        }

        public override string ToString()
        {
            return string.Format("[{0}:contract={1} in component={2}]", Name, Contract, Component);
        }

        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return false;
            }

            ServiceName that = obj as ServiceName;
            return that.GetHashCode().Equals(GetHashCode());
        }

        public override int GetHashCode()
        {
            return ToString().GetHashCode();
        }
    }
}
